package com.adams.app.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import android.database.Cursor;
import com.adams.app.dao.FoodsDateHelper;
import com.google.gson.Gson;

/**
 * @Description 美食Bean
 * 
 * @author ChengBin
 *
*/
@SuppressWarnings("serial")
public class Food extends BaseType implements Serializable {
	private static final HashMap<Long, Food> CACHE = new HashMap<Long, Food>();
	
	public Long id;
	public String name;
	public String type;
	public String tel;
	public String address;
	public String picture;
	
	
	private static void addToCache(Food food) {
		CACHE.put(food.id, food);
	}

	private static Food getFromCache(long id) {
		return CACHE.get(id);
	}

	public static Food fromJson(String json) {
		return new Gson().fromJson(json, Food.class);
	}

	public static Food fromCursor(Cursor cursor) {
		long id = cursor.getLong(cursor
				.getColumnIndex(FoodsDateHelper.FoodsDBInfo._ID));
		Food foods = getFromCache(id);
		if (foods != null) {
			return foods;
		}
		foods = new Gson().fromJson(cursor.getString(cursor
				.getColumnIndex(FoodsDateHelper.FoodsDBInfo.JSON)),
				Food.class);
		addToCache(foods);
		return foods;
	}

	public static class FoodsRequestData {

		private ArrayList<Food> cateJson;

		public ArrayList<Food> getFoods() {
			return cateJson;
		}
	}
}
